package nuc.jyg.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author Nuc YongGuang Ji
 * Created by JiYongGuang on 2017/5/17.
 */
public class TestInterceptor2 implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("TestInterceptor2 preHandle");

        //resolver garbled problems
        request.setCharacterEncoding("utf8");

      /*
        System.out.println(handler.getClass().toString());
        System.out.println(handler.getClass().getDeclaredMethods().toString());
        System.out.println("TestInterceptor2 preHandle /======== =========/");
      */


        //解决权限验证问题
    /*
        if (request.getSession().getAttribute("user") == null) {
                request.getRequestDispatcher("login.jsp").forward(request, response);
                return false;
         }
    */
        return true;
    }

    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("TestInterceptor2 postHandle");
//        modelAndView.setViewName("index.jsp");
//          modelAndView.addObject("addd",23);
//        System.out.println("TestInterceptor2 postHandle /======== =========/");
    }

    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("TestInterceptor2 afterCompletion");
    }
}
